package no.ntnu.fp.mmi;


import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;

import javax.swing.JPanel;

import no.ntnu.fp.su.Event;
import no.ntnu.fp.su.Events;
import no.ntnu.fp.su.Master;
import no.ntnu.fp.su.Message;
import no.ntnu.fp.su.Platform;




@SuppressWarnings("serial")
public class MasterWatchModel extends JPanel{
	public static final String WellProperty = "ActiveWell";
	public static final String WellListProperty = "wellList";
	public static final String PlatformProperty = "ActivePlatform";
	public static final String PlatformListProperty = "PlatformList";
	public static final String EventProperty = "Events";
	public static final String MessageListProperty = "MessageList";
	public static final String MessageProperty = "ActiveMessage";
	
	private Master master;
	private PropertyChangeSupport pcs;
	private ArrayList<Platform> platformList;
	private ArrayList<Message> messageList;
	private Events events;
	private Platform activePlatform;
	private Event activeEvent;
	private Message activeMessage;

	
	/**Constructs a mastermodel for masterpanel to use
	 * 
	 * 
	 */
	public MasterWatchModel(Master master) {
		this.master = master;
		pcs = new PropertyChangeSupport(this);
		events = master.getEvents();
		platformList = master.getPlatforms();
		messageList = master.getMessages();
	
		
//		Message melding = new Message();
//		melding.setText("Her er det en melding!!!");
//		melding.setTimestamp(new Timestamp(System.currentTimeMillis()));
//		melding.setFrom(platformList.get(0));
//		messageList.add(melding);
		
		
		MasterWatchPanel gui = new MasterWatchPanel(this);
		gui.setVisible(true);
	}
	/**
	 * 
	 * @return {@link master} master object this model uses
	 */
	public Master getMaster() {
		return master;
	}
	/**
	 * 
	 * @return activeplatform
	 */
	public Platform getActivePlatform() {
		return activePlatform;
	}
	
	/**
	 * 
	 * sets active platform
	 */
	public void setActivePlatform(Platform setPlatt) {
		Platform oldP = this.activePlatform;
		this.activePlatform = setPlatt;
		pcs.firePropertyChange(PlatformProperty, oldP, activePlatform);
	}
	
	public ArrayList<Platform> getPlatformList(){
		return this.platformList;
	}
	
	public ArrayList<Message> getMessageList(){
		return this.messageList;
	}
	
	public void setMessageList(ArrayList<Message> list){
		this.messageList= list;
	}
	
	public void setPlatformList(ArrayList<Platform> list){
		this.platformList = list;
	}


	public Events getEventList(){
		return this.events;
	}


	public Event getEvent() {
		return activeEvent;
	}

	public void setEvent(Event setev) {
		Event old = this.activeEvent;
		this.activeEvent = setev;
		pcs.firePropertyChange(EventProperty, old, setev);
	}
	
	public Message getActiveMessage(){
		return this.activeMessage;
	}
	
	public void setActiveMessage(Message setMess) {
		Message old = this.activeMessage;
		this.activeMessage = setMess;
		pcs.firePropertyChange(MessageProperty, old, activeMessage);
	}
	
	
	
	
	
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		if(pcs!=null) pcs.addPropertyChangeListener(listener);
	}
}
